1 <?php
2 ob_start();
3 include(
"header.php");
4 include(
"sidebar.php");
5 include(
"dbconnection.php");
6 ?>
7 <script type=
"text/javascript">
8 function isNumberKey(evt)
9       {
10
11          
var charCode = (evt.which) ? evt.which : event.keyCode
12         
//alert(charCode);
13          
if (charCode > 63 && charCode < 92 )
14          {
15          
return true;
16      }
17      
else if (charCode > 96 && charCode < 123 )
18          {
19          
return true;
20      }
21      
else
22      {
23         alert(
"should be alphabet");
24         
return false;
25      }
26      }
27 function validate()
28 {

29 if
(document.form1.fname.value=="")
30 {
31     alert(
"Enter First Name");
32     document.form1.fname.focus();
33     
return false;
34 }

35 if
(document.form1.lname.value=="")
36 {
37     alert(
"Enter Last Name");
38     document.form1.lname.focus();
39     
return false;
40 }

41 if
(document.form1.loginid.value=="")
42 {
43     alert(
"Enter Login ID");
44     document.form1.loginid.focus();
45     
return false;
46 }

47 if
(document.form1.password.value=="")
48 {
49     alert(
"Enter Password");
50     document.form1.password.focus();
51     
return false;
52 }

53 if
(document.form1.confpass.value=="")
54 {
55     alert(
"Please confirm the Password");
56     document.form1.confpass.focus();
57     
return false;
58 }

59 if
(document.form1.emailid.value=="")
60 {
61     alert(
"Enter Email ID");
62     document.form1.emailid.focus();
63     
return false;
64 }
65     ml = document.form1.emailid.
value;
66         pos1 = ml.indexOf(
"@")
67         pos = ml.indexOf(
" ")
68         pos2 = (pos1+
1)
69         server = ml.substring(pos2);
70         server_pos = server.lastIndexOf(
".")
71         reqtype = server.substring(server_pos+
1)
72         type_end = reqtype.substring(reqtype.length-
1)
73
74 if
(ml.length<8)
75     {
76             document.form1.emailid.focus();
77             document.form1.emailid.
select();
78             alert(
"emailid length cannot be less than 8 characters");
79             
return false;
80     }
81          
if(ml.indexOf("@")==-1)
82         {
83             document.form1.emailid.focus();
84             document.form1.emailid.
select();
85             alert(
"The emailid Address must contain '@' sign");
86             
return false;
87         }
88          
if(pos1<1)
89         {
90             document.form1.emailid.focus();
91             document.form1.emailid.
select();
92             alert(
"emailid address cannot start with '@' sign");
93             
return false;
94         }
95         
if(ml.indexOf(".")==-1)
96         {
97             document.form1.emailid.focus();
98             document.form1.emailid.
select();
99             alert(
"The emailid Address must contain '.' sign");
100             
return false;
101         }
102         
if(pos!=-1)
103         {
104             document.form1.emailid.focus();
105             document.form1.emailid.
select();
106             alert(
"The emailid Address cannot contain spaces");
107             
return false;
108         }
109         
if(server.indexOf("@")!=-1)
110         {
111             document.form1.emailid.focus();
112             document.form1.emailid.
select();
113             alert(
"A valid emailid must contain only one '@' sign");
114             
return false;
115         }
116         
if(server.indexOf(".")==0)
117         {
118             document.form1.emailid.focus();
119             document.form1.emailid.
select();
120             alert(
"There should some text between '@' and '.' sign");
121             
return false;
122         }
123         
if(reqtype=="")
124         {
125             document.form1.emailid.focus();
126             document.form1.emailid.
select();
127             alert(
"emailid Id should end with character(like .com,.net,.org)");
128             
return false;
129         }
130         
if(type_end.toUpperCase()<"A" || type_end.toUpperCase()>"Z")
131         {
132             document.form1.emailid.focus();
133             document.form1.emailid.
select();
134             alert(
"emailid Id should not end with number or symbol");
135             
return false;
136         }

137
138
139
140 if
(document.form1.mobile.value=="")
141 {
142     alert(
"Enter Mobile Number");
143     document.form1.mobile.focus();
144     
return false;
145 }

146 if
(document.form1.phone.value=="")
147 {
148     alert(
"Enter Phone No");
149     document.form1.phone.focus();
150     
return false;
151 }

152 if
(document.form1.emptype.value=="")
153 {
154     alert(
"Select Employee Typt");
155     document.form1.emptype.focus();
156     
return false;
157 }
158 }
159 </script>
160 <?php

161
162 if
(isset($_POST["submit"]))
163 {
164 $sql =
"insert into employee(fname,lname,loginid ,password,emailid,contactno1,contactno2,employeetype) values('$_POST[fname]','$_POST[lname]','$_POST[loginid]','$_POST[password]','$_POST[emailid]','$_POST[mobile]','$_POST[phone]','$_POST[emptype]')";
165
166 if
(!mysql_query($sql,$con))
167   {
168   die(
'Error: ' . mysql_error());
169   }
170   $ctins = mysql_affected_rows();
171 }

172
173 if
(isset($_POST["update"]))
174 {
175 $sql =
"update employee set fname='$_POST[fname]',lname='$_POST[lname]',loginid='$_POST[loginid]', emailid='$_POST[emailid]',contactno1='$_POST[mobile]',contactno2='$_POST[phone]' where employeeid='$_GET[empid]'";
176
177 if
(!mysql_query($sql,$con))
178   {
179   die(
'Error: ' . mysql_error());
180   }
181   $ctins = mysql_affected_rows();
182 }
183 ?>
184 <?php

185 if
(isset($_GET['empid']))
186 {
187 $sql = mysql_query(
"select * from employee where employeeid='$_GET[empid]'");
188 $row = mysql_fetch_array($sql);
189 }
190 ?>
191
192         <div id=
"main">
193
194             <a name=
"TemplateInfo"></a>
195             <h1>Add Employees</h1>
196             <h3><center><a href=
"viewemployees.php">View Employees</a></center></h3>
197             <?php

198 if
($ctins == 1)
199 {

200 if
(isset($_GET['empid']))
201 {
202         echo
"<center><b>Employees account Updated successfully...</b></center><br>";
203 }

204 else

205 {
206     echo
"<center><b>Employees account created successfully...</b></center><br>";
207 }
208 }

209 else

210 {
211     ?>
212         <form id=
"form1" name="form1" method="post" action="" onsubmit="return validate()">
213             <table width=
"371" border="0">
214               <tr>
215                 <th width=
"169" height="33" scope="row">First Name</th>
216                 <td width=
"140">
217                   <label
for="fname"></label>
218                   <input type=
"text" name="fname" value="<?php echo $row['fname']; ?>" id="fname" onKeyPress="return isNumberKey(event)"/>
219                 </td>
220               </tr>
221               <tr>
222                 <th height=
"37" scope="row">Last Name
223                   <label
for="lname"></label></th>
224                 <td><input type=
"text" name="lname" value="<?php echo $row['lname']; ?>" id="lname" onKeyPress="return isNumberKey(event)" /></td>
225               </tr>
226               <tr>
227                 <th height=
"36" scope="row">Login Id</th>
228                 <td><label
for="loginid"></label>
229                 <input type=
"text" name="loginid" id="loginid" value="<?php echo $row['loginid']; ?>" /></td>
230               </tr>
231               <tr>
232                 <th height=
"34" scope="row">Password</th>
233                 <td><label
for="password"></label>
234                 <input type=
"password" name="password" <?php if(isset($_GET['empid'])) { ?> readonly="readonly" <?php } ?> id="password" /></td>
235               </tr>
236               <tr>
237                 <th height=
"40" scope="row">Confirm Password</th>
238                 <td><label
for="confpass"></label>
239                 <input type=
"password" name="confpass" <?php if(isset($_GET['empid'])) { ?> readonly="readonly" <?php } ?> id="confpass" /></td>
240               </tr>
241               <tr>
242                 <th height=
"37" scope="row">Email ID</th>
243                 <td><label
for="emailid"></label>
244                 <input type=
"text" name="emailid" value="<?php echo $row['emailid']; ?>" id="emailid" /></td>
245               </tr>
246               <tr>
247                 <th height=
"37" scope="row">Mobile No</th>
248                 <td><label
for="mobile"></label>
249                 <input type=
"text" name="mobile" value="<?php echo $row['contactno1']; ?>" id="mobile" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/></td>
250               </tr>
251               <tr>
252                 <th scope=
"row">Phone No</th>
253                 <td><input type=
"text" name="phone" value="<?php echo $row['contactno2']; ?>" id="phone" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"/>
254                   <label
for="phone2"></label></td>
255               </tr>
256               <tr>
257                 <th scope=
"row">Employee Type</th>
258                 <td><label
for="emptype"></label>
259                   <label
for="emptype2"></label>
260                   <
select name="emptype" id="emptype2">
261                     <option
value="Employees">Employees</option>
262                     <option
value="Administrator">Administrator</option>
263                 </
select></td>
264               </tr>
265               <tr>
266                 <th scope=
"row">&nbsp;</th>
267                 <td><br /><?php
if(isset($_GET['empid'])) { ?> <input type="submit" name="update" id="submit" value="Update Employees" /><?php } else { ?> <input type="submit" name="submit" id="submit" value="Add Employees" /><?php } ?></td>
268               </tr>
269           </table>
270     </form>
271     <?php
272     }
273     ?>
274             <p>&nbsp;</p>
275 <br />
276
277         </div>
278
279 <!-- wrap ends here -->
280 </div>
281
282 <?php
283 include(
"footer.php");
284 ?>


Gõ tìm kiếm nhanh...